package com.ruoyi.web.controller.exampaperanswer;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exampaperanswer.domain.ExamPaperAnswer;
import com.ruoyi.exampaperanswer.service.IExamPaperAnswerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 答卷列表Controller
 * 
 * @author ruoyi
 * @date 2023-06-25
 */
@Controller
@RequestMapping("/exampaperanswer/exampaperanswerList")
public class ExamPaperAnswerController extends BaseController
{
    private String prefix = "exampaperanswer/exampaperanswerList";

    @Autowired
    private IExamPaperAnswerService examPaperAnswerService;

    @RequiresPermissions("exampaperanswer:exampaperanswerList:view")
    @GetMapping()
    public String exampaperanswerList()
    {
        return prefix + "/exampaperanswerList";
    }

    /**
     * 查询答卷列表列表
     */
    @RequiresPermissions("exampaperanswer:exampaperanswerList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamPaperAnswer examPaperAnswer)
    {
        startPage();
        List<ExamPaperAnswer> list = examPaperAnswerService.selectExamPaperAnswerList(examPaperAnswer);
        return getDataTable(list);
    }

    /**
     * 导出答卷列表列表
     */
    @RequiresPermissions("exampaperanswer:exampaperanswerList:export")
    @Log(title = "答卷列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamPaperAnswer examPaperAnswer)
    {
        List<ExamPaperAnswer> list = examPaperAnswerService.selectExamPaperAnswerList(examPaperAnswer);
        ExcelUtil<ExamPaperAnswer> util = new ExcelUtil<ExamPaperAnswer>(ExamPaperAnswer.class);
        return util.exportExcel(list, "答卷列表数据");
    }

    /**
     * 新增答卷列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存答卷列表
     */
    @RequiresPermissions("exampaperanswer:exampaperanswerList:add")
    @Log(title = "答卷列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamPaperAnswer examPaperAnswer)
    {
        return toAjax(examPaperAnswerService.insertExamPaperAnswer(examPaperAnswer));
    }

    /**
     * 修改答卷列表
     */
    @RequiresPermissions("exampaperanswer:exampaperanswerList:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ExamPaperAnswer examPaperAnswer = examPaperAnswerService.selectExamPaperAnswerById(id);
        mmap.put("examPaperAnswer", examPaperAnswer);
        return prefix + "/edit";
    }

    @RequiresPermissions("exampaperanswer:exampaperanswerList:watch")
    @GetMapping("/watch/{id}")
    public String watch(@PathVariable("id") Long id, ModelMap mmap)
    {
        ExamPaperAnswer examPaperAnswer = examPaperAnswerService.selectExamPaperAnswerById(id);
        mmap.put("examPaperAnswer", examPaperAnswer);
        return prefix + "/watch";
    }

    /**
     * 修改保存答卷列表
     */
    @RequiresPermissions("exampaperanswer:exampaperanswerList:edit")
    @Log(title = "答卷列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamPaperAnswer examPaperAnswer)
    {
        return toAjax(examPaperAnswerService.updateExamPaperAnswer(examPaperAnswer));
    }

    /**
     * 删除答卷列表
     */
    @RequiresPermissions("exampaperanswer:exampaperanswerList:remove")
    @Log(title = "答卷列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examPaperAnswerService.deleteExamPaperAnswerByIds(ids));
    }
}
